﻿using CL.Business.BLL;
using CL.Tools.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CL.Admin.admin.promotion
{
    public partial class promotion_list :UI.AdminPage
    {
        protected string startTime = string.Empty;
        protected string endTime = string.Empty;
        protected int totalCount;
        protected int page;
        protected int pageSize;
        protected string searchKey;
        protected void Page_Load(object sender, EventArgs e)
        {
            this.pageSize = GetPageSize(10); //每页数量
            this.startTime = QPRequest.GetQueryString("StartTime");
            if (string.IsNullOrEmpty(this.startTime))
                this.startTime = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");
            this.endTime = QPRequest.GetQueryString("endTime");
            if (string.IsNullOrEmpty(this.endTime))
                this.endTime = DateTime.Now.ToString("yyyy-MM-dd");
            if (!IsPostBack)
            {
                RptBind();
            }
        }

        protected void RptBind()
        {
            this.page = QPRequest.GetQueryInt("page", 1);
            searchKey = QPRequest.GetQueryString("searchkey");
            AgencyUserBLL bll = new AgencyUserBLL();
            txtStartTime.Text = this.startTime;
            txtEndTime.Text = this.endTime;
            this.rptList.DataSource = bll.QueryExtendDetails(0 ,this.startTime, this.endTime, page, pageSize, searchKey, ref this.totalCount);
            this.rptList.DataBind();

            //绑定页码
            txtPageNum.Text = this.pageSize.ToString();
            List<string> listParam = new List<string>();
            listParam.Add("__id__");
            listParam.Add(this.startTime);
            listParam.Add(this.endTime);
            listParam.Add(searchKey);
            string pageUrl = Utils.CombUrlTxt("promotion_list.aspx", "page={0}&StartTime={1}&endTime={2}&searchkey={3}", listParam.ToArray());
            PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8);
        }
        #region 返回每页数量=============================
        private int GetPageSize(int _default_size)
        {
            int _pagesize;
            if (int.TryParse(Utils.GetCookie("promotion_list_page_size", "QPcmsPage"), out _pagesize))
            {
                if (_pagesize > 0)
                {
                    return _pagesize;
                }
            }
            return _default_size;
        }


        #endregion

        protected void txtPageNum_TextChanged(object sender, EventArgs e)
        {
            int _pagesize;
            if (int.TryParse(txtPageNum.Text.Trim(), out _pagesize))
            {
                if (_pagesize > 0)
                {
                    Utils.WriteCookie("promotion_list_page_size", "QPcmsPage", _pagesize.ToString(), 14400);
                }
            }
            Response.Redirect("promotion_list.aspx");
        }
    }
}